package models

type OutOrderDetail struct {
	Model
	OutOrderId  int     `json:"out_order_id"`
	Price       float64 `json:"price"`
	Num         int     `json:"num"`
	ProductId   int     `json:"product_id"`
	ProductName string  `json:"product_name"`
	ProductSpec string  `json:"product_spec"`
}

func AddOutOrderDetail(data map[string]interface{}, mainId int) bool {
	db.Create(&OutOrderDetail{
		OutOrderId:  mainId,
		Price:       data["price"].(float64),
		Num:         data["num"].(int),
		ProductId:   data["product_id"].(int),
		ProductName: data["product_name"].(string),
		ProductSpec: data["product_spec"].(string),
	})
	return true
}

func EditOutOrderDetail(data OutOrderDetail) bool {
	db.Model(&OutOrderDetail{}).Where("id=?", data.ID).Update(&OutOrderDetail{
		Price: data.Price,
		Num:   data.Num,
	})
	return true
}
